def zscg():
    name_list = ['zhangsan', 'lisi', 'wangwu']
    print(name_list[2])
    print(name_list.index('wangwu'))
    name_list[1] = '李四'
    print(name_list)
    name_list.append('haoliu')
    print(name_list)
    name_list.insert(1, 'xiaomei')
    print(name_list)
    temp_list = ['the cow', 'pigg', 'kelie']
    name_list.extend(temp_list)
    print(name_list)
    name_list.remove('pigg')
    print(name_list)
    name_list.pop()
    print(name_list)
    name_list.clear()
    print(name_list)


# zscg()
def tongji():
    name_list = ['zhangsan', 'lisi', 'wangwu']
    list_len = len(name_list)
    print(list_len)
    count = name_list.count('zhangsan')
    print(count)
    num_list = [4, 1, 5, 9, 8]
    num_list.sort()  # 升序
    print(num_list)
    num_list.sort(reverse=True)  # 升序反转
    print(num_list)
    num_list.reverse()  # 降序
    print(num_list)
    for my_name in name_list:
        print('my name is %s' % my_name)


# tongji()
def liebiao():
    a = [x for x in range(10)]
    print(a)
    b = [j for i in range(10) for j in range(i)]
    print(b)
    c = [[col * row for col in range(5)] for row in range(5)]
    print(c)
    d = [j for i in c for j in i]  # 二维转一维
    print(d)
    e = [x for x in range(10) if x % 2 == 0]  # 只筛选偶数
    print(e)
    f = [x if x % 2 == 0 else x ** 2 for x in range(10)]  # if _else三元表达式
    print(f)


liebiao()


def special_list():
    a = [1, 2, 3, 4, 5]
    b = [1, 2, 3]
    c = [0] * 50  # 初始化50个列表元素
    print(c)
    print(id(a))
    a += b  # 等价于extend a 的id不变
    print(id(a))
    a = a + b  # a的id改变
    print(id(a))


special_list()


def demo_list():
    demolist = [3, 3, 7, 7, 9, 6, 6, 10]
    result = 0
    for i in demolist:
        result ^= i
    print(result)
    split_flag = result & -result
    result1 = 0
    result2 = 0
    for i in demolist:
        if i & split_flag:
            result1 ^= i
        else:
            result2 ^= i
    print(f'出现一次的两个数分别是{result1},{result2}')


demo_list()
